package dpss.commons;

import java.io.Serializable;

/**
 * The player account holding information about a single player
 * 
 * @author musab.mirza
 * 
 */
public class Player implements Serializable {

	private static final long serialVersionUID = 1L;
	
	// Player properties
	private String username, password, firstName, lastName, ipAddress;
	private Integer age;
	boolean online;

	/**
	 * Default player params
	 * @throws Exception 
	 */
	public Player(String username, String password, Integer age, String ipAddress, String firstName, String lastName, boolean online) throws Exception {
		
		
		username = username.trim().toLowerCase();
		firstName = firstName.trim();
		lastName = lastName.trim();
		password = password.trim();
		ipAddress = ipAddress.trim();

		// Perform validations
		if (username.matches(".*\\d.*")){
			throw new Exception("Username should not contain digits");
		}
		if ( !username.equalsIgnoreCase("admin") && (username.length() < 6 || username.length() > 15)){
			throw new Exception("Username should be between 6 and 15 characters long");
		}
		if ( !username.equalsIgnoreCase("admin") && password.length() < 6){
			throw new Exception("The password cannot be less than 6 characters");
		}
		if (age < 5){
			throw new Exception("Age should be greater than or equal to 5");
		}
		if (firstName.isEmpty() || lastName.isEmpty()){
			throw new Exception("Both first and last names are required");
		}
		if (firstName.isEmpty() || lastName.isEmpty()){
			throw new Exception("The ipAddress is empty");
		}
		if(firstName.matches(".*\\d.*") || lastName.matches(".*\\d.*")){
			throw new Exception("FirstName or LastName should not contain digits");
		}
		
		this.username = username;
		this.password = password;
		
		this.firstName = firstName;
		this.lastName = lastName;
		this.ipAddress = ipAddress;
		this.age = age;
		this.online = online;
	}

	public String getUsername() {
		return username;
	}

	public String getPassword() {
		return password;
	}

	public String getFirstName() {
		return firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public String getIpAddress() {
		return ipAddress;
	}

	public Integer getAge() {
		return age;
	}

	public boolean isOnline() {
		return online;
	}
	
	public void setOnline(boolean online) {
		this.online = online;
	}

}
